import * as axios from "axios";
import { AxiosResponse, InternalAxiosRequestConfig, AxiosInstance } from "axios";


const baseURL: string = process.env.VUE_APP_URL

const service: AxiosInstance = axios.default.create({
    baseURL,
    timeout: 100000,
    maxContentLength: 4000
})

service.interceptors.request.use(
    (config: InternalAxiosRequestConfig) => {
        return config;
    },
    (error: string) => {
        Promise.reject(error)
    }
);

service.interceptors.response.use(
    (response: AxiosResponse) => {
        if (response.status !== 200) {
            alert('fail')
        } else {
            return response.data
        }
    },
    (error: string) => {
        Promise.reject(error)
    }
);

export interface AjaxResponse {
    code: number;
    data: [];
    message: string;
}
export default service
